
import apis from '../../http/apis/apis'

export default {
    namespaced: true,
    state: {
        currentUser: {},
        isCollapse: false,
        nowBreadcrumb: [],
        breadcrumbDate: [{
            key: 'system',
            name: '系统',
            path: 'system',
            children: [{
                key: 'admin',
                name: "管理员管理",
                path: "admin",
                children: [{
                    key: "addadmin",
                    name: "新增管理员",
                    path: "addadmin",
                }, {
                    key: "adminlist",
                    name: "管理员列表",
                    path: "adminlist"
                },{
                    key: "updataadmin",
                    name: "修改管理员",
                    path: "updataadmin"
                }]
            }, {
                key: 'user',
                name: "用户管理",
                path: "user",
                children: [{
                    key: "adduser",
                    name: "新增用户",
                    path: "adduser",
                }, {
                    key: "userlist",
                    name: "用户列表",
                    path: "userlist"
                }]
            }, {
                key: 'order',
                name: "订单管理",
                path: "order",
                children: [{
                    key: "addorder",
                    name: "添加订单",
                    path: "addorder",
                }, {
                    key: "orderlist",
                    name: "订单列表",
                    path: "orderlist"
                }]
            }, {
                key: 'car',
                name: "车辆管理",
                path: "car",
                children: [{
                    key: "addcar",
                    name: "添加车辆",
                    path: "addcar",
                }, {
                    key: "carlist",
                    name: "车辆列表",
                    path: "carlist"
                }]
            },{
                key: 'customercomme',
                name: "评价管理",
                path: "customercomme",
                children: [{
                    key: "addcarcoments",
                    name: "用户评价",
                    path: "addcarcoments",
                }]
            },{
                key: 'carcomemnts',
                name: "评价管理",
                path: "carcomemnts",
                children: [{
                    key: "addcarcoments",
                    name: "车辆评价",
                    path: "addcarcoments",
                }]
            }
            ]
        }]
    },
    mutations: {
        switchIsCollapse(state) {
            state.isCollapse = !state.isCollapse
        },
        setNowBreadcrumb(state, key) {
            const data = state.breadcrumbDate;
            let strArr = [];
            let isOk = false;
            //遍历对象组
            function createMowBreadcrumb(data, key) {
                for (const item of data) {
                    strArr.push(item);
                    if (item.key == key) {
                        isOk = true;
                        return;
                    } else {
                        if (item.children && item.children.length > 0) {
                            createMowBreadcrumb(item.children, key);
                            if (isOk) return;
                        }
                    }
                    strArr.pop();
                }
            }
            createMowBreadcrumb(data, key);

            state.nowBreadcrumb = [];

            strArr.reduce((url, item) => {
                let path = url + '/' + item.path;
                state.nowBreadcrumb.push({
                    name: item.name,
                    path
                })
                return path;
            }, "");

        },
        changeCurrentUser(state, val) {
            state.currentUser = val
        }
    },
    actions: {


    }
}